package chances.epg.data.service;

import java.util.List;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import chances.epg.commons.log.EpgLogFactory;
import chances.epg.entity.biz.CornerMark;
import chances.epg.entity.content.ContentBaseTag;
import chances.epg.entity.content.ContentOpTag;
import chances.epg.entity.content.ContentType;

/**
 * 基础数据服务.
 * @author libf
 *
 */
@Service
public class BaseDataLoader extends EpgService{
	private static Logger logger = EpgLogFactory.getSystemLogger();
	
	@PostConstruct
	@Scheduled(cron="0 */5 * * * ?")
	public void loadDatas() {
		this.loadAllCornerMarks();
		this.loadAllTypes();
		this.loadAllBaseTags();
		this.loadAllOpTags();
	}
	
	@SuppressWarnings("unchecked")
	public void loadAllCornerMarks() {
		logger.debug("Loading cornerMarks...");
		List<CornerMark> result = (List<CornerMark>)this.queryForList("getAllCornerMarks");
		BaseDataRepertory.getInstance().initCornerMarks(result);
	}
	
	@SuppressWarnings("unchecked")
	public void loadAllTypes() {
		logger.debug("Loading content types...");
		List<ContentType> allTypes = (List<ContentType>)this.queryForList("getAllContentTypes");
		BaseDataRepertory.getInstance().initTypes(allTypes);
	}
	
	@SuppressWarnings("unchecked")
	public void loadAllBaseTags() {
		logger.debug("Loading content base tags...");
		List<ContentBaseTag> allTags = (List<ContentBaseTag>)this.queryForList("getAllContentBaseTags");
		BaseDataRepertory.getInstance().initBaseTags(allTags);
	}
	
	@SuppressWarnings("unchecked")
	public void loadAllOpTags() {
		logger.debug("Loading content base tags...");
		List<ContentOpTag> allTags = (List<ContentOpTag>)this.queryForList("getAllContentOpTags");
		BaseDataRepertory.getInstance().initOpTags(allTags);
	}
}
